{% extends "based/based_no_head.html" %}
{% block title %}{{_("找回密码")}}-{% endblock %}
{% block content %}
<div class="row osr-edit-page osr-login-page">
    <section class="osr-panel">
        <div id="app">
            <p class="text-center">
                <img class="osr-logo" src="{{g.site_global.site_config.LOGO_IMG_URL_SECONDAEY}}" alt="Logo">
            </p>
            <div class="form-group">
              <input name="email" id="email" class="form-control osr-input" type="email" v-model="email"
                     placeholder="电子邮箱"
                     data-bv-emailAddress="true" data-bv-emailAddress-message="{{_('邮箱地址不合法')}}"
                    data-bv-notempty-message="{{_('邮箱地址不能为空')}}" required
                     placeholder="电子邮箱"  required/>
            </div>
            <div class="form-group">
              <input name="password" id="password" class="form-control osr-input" type="password" v-model="password"
                     minlength="8" placeholder="{{_('输入密码')}}"
                     data-bv-notempty-message="{{_('至少8个字符')}}"
                     data-bv-stringLength-message="{{_('至少8个字符')}}" required/>
            </div>
            <div class="form-group">
              <input name="password2" id="password2" class="form-control osr-input" type="password" v-model="password2"
                     placeholder="{{_('再次输入密码')}}"
                     data-bv-identical="true"
                     data-bv-notempty-message="{{_('至少8个字符')}}"
                     data-bv-identical-message="{{_('前后密码不一致')}}"
                     data-bv-identical-field="password" required/>
            </div>

            {% include 'module/_send_code.html' %}

            <div class="form-group">
                <button v-on:click="reset()" class="btn-block btn osr-btn btn-info osr-submit-btn">
                    {{_('重设密码')}}
                </button>
            </div>

            <div class="form-group osr-color-success">
                <i class="fa fa-sign-in"></i>
                <a href="/osr-admin/sign-in">{{_("回到登录")}}</a>
            </div>

            <div class="form-group">
                {% include 'module/_no_header_select_lan.html' %}
            </div>
        </div>
    </section>
</div>
<script>
    var vue = new Vue({
      el: '#app',
      delimiters:['{[', ']}'],
      data: {
        email:'',
        password: '',
        password2: '',
        email_code:"",
        //_send_code.html需要参数
        send_code_to_exist_account:1,
        img_code_url_obj:{},
        img_code_url:"",
        img_code:""
      }
    })

    // 页面一加载完就自动执行
    $(document).ready(function(){
        (function($) {
            if ($.AMUI && $.AMUI.validator) {
            // 增加多个正则
            $.AMUI.validator.patterns = $.extend($.AMUI.validator.patterns, {
                 osrEmail:/^[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,
                 osrPassword:/^(?!(?:\d+|[a-zA-Z]+)$)[\da-zA-Z]{8,}$/
            });
            // 增加单个正则
            //$.AMUI.validator.patterns.osrEmail = /^[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
        }
        })(window.jQuery);

        var result = osrHttp("GET","/api/global");
        result.then(function (r) {
            if(r.data.is_authenticated){
                window.location.href = "/";
            }
        })
    });

   function reset(){
        formValidate();
        var d = {   email:vue.email,
                    password:vue.password,
                    password2:vue.password2,
                    email_code:vue.email_code,
                }
        // 提交数据
        osrHttp("PUT","/api/account/password/retrieve", d);
   }

</script>
{% endblock %}

